﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;

namespace EventPlanner.Validation
{
    
    [AttributeUsage(AttributeTargets.Property)]
    public class FechaValida : ValidationAttribute, IClientValidatable
    {
     

        public override bool IsValid(object value)
        {
            DateTime dateStart = (DateTime)value;
            // Meeting must start in the future time.
            String strActu = DateTime.Now.ToString("yyyyMMdd");
            String strInicio = dateStart.ToString("yyyyMMdd");

            return (Convert.ToInt32(strInicio) >= Convert.ToInt32(strActu));
        }

        public class ModelClientValidationDateRule : ModelClientValidationRule
        {
            public ModelClientValidationDateRule(string errorMessage)
            {
                base.ErrorMessage = errorMessage;
                base.ValidationType = "fecha";

            }
        }

        public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            yield return new ModelClientValidationDateRule(FormatErrorMessage(metadata.GetDisplayName()));
        }
    }
}